package com.sl.binarytree;

import java.util.ArrayDeque;

/**
 * Created by lisulong on 2019/4/1.
 * 广度遍历二叉树
 */
public class BreadthFirstSearch {

    public void levelOrderTraversal(ListNode node) {
        if (node == null) {
            System.out.print("empty tree");
            return;
        }
        ArrayDeque<ListNode> deque = new ArrayDeque<ListNode>();
        deque.add(node);
        while (!deque.isEmpty()) {
            ListNode rnode = deque.remove();
            System.out.print(rnode.strVal + "  ");
            if (rnode.left != null) {
                deque.add(rnode.left);
            }
            if (rnode.right != null) {
                deque.add(rnode.right);
            }
        }
    }

}
